from token_manager import TokenManager
import requests

def example_ebay_api_call():
    # 创建令牌管理器实例
    token_manager = TokenManager()
    
    # 获取访问令牌
    access_token = token_manager.get_token()
    
    if not access_token:
        print("Failed to get access token")
        return
    
    # 使用令牌调用eBay API示例
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json'
    }
    
    # 示例：获取账户信息
    try:
        response = requests.get(
            'https://api.ebay.com/sell/account/v1/privilege',
            headers=headers
        )
        
        if response.status_code == 200:
            print("API调用成功！")
            print(response.json())
        else:
            print(f"API调用失败: {response.status_code}")
            print(response.text)
            
    except Exception as e:
        print(f"发生错误: {e}")

def check_token_status():
    # 创建令牌管理器实例
    token_manager = TokenManager()
    
    # 获取令牌信息
    token_info = token_manager.get_token_info()
    
    print("\n令牌状态信息:")
    print(f"状态: {token_info['status']}")
    print(f"过期时间: {token_info['expires_at']}")
    print(f"权限范围: {token_info['scopes']}")

if __name__ == "__main__":
    print("检查令牌状态...")
    check_token_status()
    
    print("\n执行API调用示例...")
    example_ebay_api_call() 